#pragma once

#include <vector>

namespace solution_063
{

class Solution
{
public:
    int uniquePathsWithObstacles(std::vector< std::vector<int> >& obstacleGrid)
    {
        obstacleGrid[0][0] ^= 1;
        for (int row = 1; row < (int)obstacleGrid.size(); ++row)
            obstacleGrid[row][0] = obstacleGrid[row][0] ? 0 : obstacleGrid[row-1][0];
        for (int col = 1; col < (int)obstacleGrid.front().size(); ++col)
            obstacleGrid[0][col] = obstacleGrid[0][col] ? 0 : obstacleGrid[0][col-1];
        for (int row = 1; row < (int)obstacleGrid.size(); ++row) {
            for (int col = 1; col < (int)obstacleGrid.front().size(); ++col) {
                obstacleGrid[row][col] = obstacleGrid[row][col] ? 0 :
                                         obstacleGrid[row][col-1] +
                                         obstacleGrid[row-1][col];
            }
        }
        return obstacleGrid.back().back();
    }
};

}  /* namespace solution_063 */
